package com.jeff.tianti.exception;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class FirstIntercept implements HandlerInterceptor {
    /*  该方法在目标方法之前之前进行拦截调用
     * 若该方法返回true，则会继续调用后续的拦截器和目标方法
     * 若方法返回false，则会终止后续拦截器和目标方法的执行。
     * preHandle--》目标方法 --》postHandle--》afterCompletion
     *
     * 权限 日志 事务
     */
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
                             Object handler) throws Exception {
//        System.out.println("FirstIntercept  preHandle ");
        //return false;
        return true;
    }

    /*调用目标方法之后渲染视图之前
     * 可以对请求域中的属性或者视图做出修改
     * */
    public void postHandle(HttpServletRequest request, HttpServletResponse response,
                           Object handler, ModelAndView modelAndView) throws Exception {
        // TODO Auto-generated method stub
//        System.out.println("FirstIntercept  postHandle ");
    }

    /*渲染视图之后
     *  释放资源
     * */
    public void afterCompletion(HttpServletRequest request,
                                HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
        // TODO Auto-generated method stub
//        System.out.println("FirstIntercept  afterCompletion ");
    }
}
